package com.xb.loan.fund.impl;

import com.xb.loan.fund.dao.CashVerifyErrorDao;
import com.xb.loan.fund.dao.bean.CashVerifyError;
import com.xb.loan.fund.service.ICashVerifyErrorService;
import com.xb.loan.fund.service.bean.CashVerifyErrorVO;
import com.xb.loan.log.exception.BizException;
import com.xb.loan.util.cache.redis.comm.FormatOperation;
import com.xb.loan.util.common.ObjectOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * 日志记录
 */

@Service("cashVerifyErrorService")
public class CashVerifyErrorServiceImpl implements ICashVerifyErrorService {

    @Autowired
    CashVerifyErrorDao verifyErrorDao;

    @Override
    public int addCashVerifyError(CashVerifyErrorVO cashVerifyErrorVO)  throws BizException {
    	cashVerifyErrorVO.setCreateTime(FormatOperation.formatDateToYMDHms14(new Date()));
        CashVerifyError cashVerifyError= ObjectOperation.convertByClasses(cashVerifyErrorVO, CashVerifyError.class);
        return verifyErrorDao.insert(cashVerifyError);
    }

    @Override
    public int deleteCashVerifyErrorById(String fundLimitId)  throws BizException{
        return verifyErrorDao.deleteByPrimaryKey(fundLimitId);
    }

    @Override
    public void updateErrorStatus(String fundLimitId, Integer status) throws BizException {
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("fundLimitId", fundLimitId);
        map.put("status", status);
        
        verifyErrorDao.updateErrorStatus(map);
    }

    @Override
    public List<CashVerifyErrorVO> queryCashVerifyError(String platId, String userId, String partnerId,
                                                        Integer orderType, Integer errorType, Integer status,
                                                        String startTime, String endTime, int pageNum, int numPerPage) throws BizException {
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("platId", platId);
        map.put("userId", userId);
        map.put("partnerId", partnerId);
        map.put("orderType", orderType);
        map.put("errorType", errorType);
        map.put("status", status);
        map.put("startTime", startTime);
        map.put("endTime", endTime);
        map.put("pageNum", pageNum);
        map.put("numPerPage", numPerPage);
        
        List<CashVerifyError> list=verifyErrorDao.queryCashVerifyError(map);
        
        List<CashVerifyErrorVO> listResult = new ArrayList<CashVerifyErrorVO>();
        if (list != null && list.size() > 0) {
            listResult.addAll(ObjectOperation.convertByClassesList(list, CashVerifyErrorVO.class));
            return listResult;
        } else {
            return null;
        }
    }

    @Override
    public int queryCashVerifyErrorCount(String platId, String userId, String partnerId, Integer orderType,
                                         Integer errorType, Integer status, String startTime, String endTime) throws BizException {
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("platId", platId);
        map.put("userId", userId);
        map.put("partnerId", partnerId);
        map.put("orderType", orderType);
        map.put("errorType", errorType);
        map.put("status", status);
        map.put("startTime", startTime);
        map.put("endTime", endTime);
        
        return verifyErrorDao.queryCashVerifyErrorCount(map);
    }

}
